import XEUtils from 'xe-utils';
import themeCustom from './theme-custom'
import themeDefault from './theme-default'


const modules = import.meta.glob('./theme-ad*.js', { eager: true });
const themeStore = {}
for (const path in modules) {
	const regxRes = path.match(/^.\/theme-([a-z]+[1-9]+)\.js$/, 'g') 
	themeStore[regxRes[1]] = modules[path].default
}
// 环境变量
const envMode = import.meta.env.MODE
/**
 * 获取配置的主题样式
 *
 * @returns Object 配置信息
 */
export const getThemeConfig = () => {
	let result = { ...themeDefault, ...themeCustom };
	let envTheme = themeStore[envMode] || {};
	let envConfig = {};
	if (import.meta.env.VITE_CUSTOM_THEME_CONFIG) {
		envConfig = JSON.parse(import.meta.env.VITE_CUSTOM_THEME_CONFIG);
	}
	result = { ...result, ...envTheme, ...envConfig };
	return XEUtils.clone(result, true);
};
